<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区 -->
    <el-card>
      <el-row :gutter="25">
        <el-col :span="4">
          <el-button type="primary" @click="User">文件管理</el-button>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" @click="Submit">上传文件</el-button>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" @click="addDialogVisible = true">新建文件夹</el-button>
        </el-col>

        <el-col :span="4">
          <el-button type="primary" ><a href="https://www.ljserver.cn/wpsonline/#/dbFile">在线编辑文件</a></el-button>
        </el-col>
      </el-row>


    </el-card>

    <!-- 创建新用户对话框 -->
    <el-dialog title="添加文件" :visible.sync="addDialogVisible" width="50%"
               @close="addDialogClosed">
      <!-- 内容主体区域 -->
      <el-form :model="addForm" :rules="addFormRules"
               ref="addFormRef" label-width="70px">

        <el-form-item label="文件夹名" prop="fname">
          <el-input v-model="addForm.fname"></el-input>

        </el-form-item>




      </el-form>
      <!-- 内容底部区域 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addUser">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 修改用户对话框 -->
    <el-dialog title="重命名" :visible.sync="editDialogVisible" width="50%" @colse="editDialogClosed">
      <el-form :model="editForm" :rules="editFormRules" ref="editFormRef" label-width="70px">
        <!-- 用户名 -->
        <el-form-item label="文件名" prop="filename">
          <el-input v-model="editForm.Filename" disabled></el-input>
        </el-form-item>
        <!-- 密码 -->
        <el-form-item label="上传时间" prop="ctime">
          <el-input v-model="editForm.ctime"></el-input>
        </el-form-item>
        <!-- 邮箱 -->
        <!--        <el-form-item label="大小" prop="min">-->
        <!--          <el-input v-model="editForm.email"></el-input>-->
        <!--        </el-form-item>-->
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editUserInfo">确 定</el-button>
      </span>
    </el-dialog>
<table  class="table table-bordered table-hover">
    <thead>

    </thead>
    <tbody id="zuoye">


    </tbody>
</table>
  </div>
</template>

<script>
import axios from "axios";
import $ from 'jquery';
import router from "@/router";
var user=window.sessionStorage.getItem('username');

export default {
  data() {
    return {
      // 请求数据
      queryInfo: {
        query: "",
        // pageNum: 1,
        // pageSize: 5
      },
      userlist: [],// 用户列表

      total: 0, // 最大数据记录
      addDialogVisible: false ,// 对话框显示
      // 添加用户表单项
      addForm: {
        fname:'',


      },
      // 控制修改用户对话框显示/隐藏
      editDialogVisible:false,
      // 修改用户信息
      editForm:{},
      // 验证规则
      addFormRules:{
        username:[
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 5, max: 8, message: "长度在 5 到 8 个字符", trigger: "blur" }
        ],
        password:[
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 6, max: 8, message: "长度在 6 到 8 个字符", trigger: "blur" }
        ],
        email:[
          { required: true, message: "请输入邮箱", trigger: "blur" },
          { min: 5, max: 15, message: "请输入正确邮箱地址", trigger: "blur" }
        ],
      },
      // 修改用户表单验证规则
      editFormRules:{
        password:[
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 6, max: 8, message: "长度在 6 到 8 个字符", trigger: "blur" }
        ],
        email:[
          { required: true, message: "请输入邮箱", trigger: "blur" },
          { min: 5, max: 15, message: "请输入正确邮箱地址", trigger: "blur" }
        ],
      },
    };
  },
  created() {
    this.getUserList();
  },
  methods: {
    Eidor(){
      this.$router.push('https://www.ljserver.cn/wpsonline/#/dbFile');
    },
   getList(){
  this.$router.push('/goods');
},
  User(){
    this.$router.push('/user');
  },
  Submit(){
    this.$router.push('/Introduction');
  },
    async getUserList() {
     var flame=window.sessionStorage.getItem("fname");
      // 调用post请求
      $.ajax({
        url: "http://localhost:9071/floders?user="+user,
        dataType: "json",
        success: function (resp) {
          $("#zuoye").empty();

          $.each(resp, function (i, n) {


            $("#zuoye").append("<tr><td><el-button @click='getList()' type=\"text\" size=\"medium\"><a href='http://localhost:8080/#/reset?'><i class=\"el-icon-folder-checked\" style=\"font-size: 60px; color: darkgoldenrod\"></i></a><p style=\"color: black\"></p></el-button></td><td class='m'><a href='http://localhost:8080/#/goods'>"+n.fname+"</a></td><td>"+n.ctime+"</td><td></p></el-button></td><td><el-button type='text' size='medium'><i class='el-icon-download'></i></el-button></td><td><el-button type='text' size='medium'><i class='el-icon-delete'></i></el-button></td><td><el-button type=\"text\" size=\"medium\"><i class=\"el-icon-more-outline\"></i></el-button></td></tr>");

          })
        }

      })
    },
    // 监听pageSize改变的事件
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize;
      this.getUserList(); // 数据发生改变重新申请数据
    },
    // 监听pageNum改变的事件
    handleCurrentChange(newPage) {
      this.queryInfo.pageNum = newPage;
      this.getUserList(); // 数据发生改变重新申请数据
    },
    // 修改用户状态
    async userStateChanged(userinfo) {
      const { data: res } = await this.$http.put(
          `states?id=${userinfo.id}&state=${userinfo.state}`
      );
      if (res != "success") {
        userinfo.state = !userinfo.state;
        return this.$message.error("操作失败！！！");
      }
      this.$message.success("操作成功！！！");
    },
    // 监听添加用户
    addDialogClosed(){
      this.$refs.addFormRef.resetFields();// 重置表单项
    },

    addUser(){
      this.$refs.addFormRef.validate(async valid =>{
        console.log(valid);
        if( !valid ) return;
        // 发起请求
        const {data:res} = await this.$http.post("floder?user="+user,this.addForm);
        window.sessionStorage.setItem("fname",this.addForm.fname);

        if (res != "success") {

          userinfo.state = !userinfo.state;
          return this.$message.error("操作失败！！！");
        }
        this.$message.success("操作成功！！！");
        //隐藏
        this.addDialogVisible = false;
        this.getUserList();
      })
    },

    // 展示修改框
    async showEditDialog(id){

      const {data:res} = await this.$http.get("getUpdate?id="+id);
      // if (res != "success") {
      // userinfo.state = !userinfo.state;
      // return this.$message.error("操作失败！！！");
      // }
      // this.$message.success("操作成功！！！");

      this.editForm = res;
      this.editDialogVisible = true;
    },
    // 关闭窗口
    editDialogClosed(){
      this.$refs.editFormRef.resetFields();
    },
    // 确认修改
    editUserInfo(){
      this.$refs.editFormRef.validate(async valid =>{
        console.log(valid);
        if( !valid ) return;
        // 发起请求
        const {data:res} = await this.$http.put("editUser",this.editForm);
        console.log(res);
        if (res != "success") return this.$message.error("操作失败！！！");
        this.$message.success("操作成功！！！");
        //隐藏
        this.editDialogVisible = false;
        this.getUserList();
      });
    },
    // 删除按钮
    async deleteUser(id){
      // 弹框
      const confirmResult = await this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).catch(err => err)
      // 成功删除为confirm 取消为 cancel
      if(confirmResult!='confirm'){
        return this.$message.info("已取消删除");
      }
      const {data:res} = await this.$http.delete("deleteFile?id="+id);
      if (res != "success") {
        return this.$message.error("操作失败！！！");
      }
      this.$message.success("操作成功！！！");
      this.getUserList();
    },
  }
};
</script>






<!--      <el-button @click="picList" type="text" size="medium"><i class="el-icon-folder-checked" style="font-size: 60px; color: darkgoldenrod"></i><p style="color: black">图片</p></el-button>-->
<!--      <el-button @click="getMusic" type="text" size="medium"><i class="el-icon-folder-checked" style="font-size: 60px; color: darkgoldenrod"></i></el-button>-->
<!--      <div class="form-group">-->
<!--        <button @click="getList" class="btn btn-success">文件</button>-->
<!--      </div>-->
<!--      <div class="form-group">-->
<!--        <button @click="picList" class="btn btn-success">图片</button>-->
<!--      </div>-->




import axios from "axios";
import $ from 'jquery';
import router from "@/router";



      // options: {
      //   // 可通过 https://github.com/simple-uploader/Uploader/tree/develop/samples/Node.js 示例启动服务
      //   target: 'http://localhost:9036/upload',
      //
      //   testChunks: false
      // },
      // attrs: {
      //   accept: 'image/*'
      // }




   // Manger(){
   //   this.$router.push("/user")
   // },


    // 添加用户

    // 展示修改框



    // getMusic(){
    //
    //   this.$router.push('/rights');
    // },


      // $.ajax({
      //   url: "http://localhost:9018/file",
      //   dataType: "json",
      //   success: function (resp) {
      //     $("#zuoye").empty();
      //
      //     $.each(resp, function (i, n) {
      //
      //

      //       this.$router.push({path: "/goods"});
      //     })
      //   }
      //
      // })

    // picList() {
    //   this.$router.push({path: "/sport"});
      //   $.ajax({
      //     url: "http://localhost:9019/picture",
      //     dataType: "json",
      //     success: function (resp) {
      //       $("#pic").empty();
      //
      //       $.each(resp, function (i, n) {
      //
      //
      //
      //         this.$router.push({ path: "/picture"});
      //       })
      //     }
      //
      //   })
      //
      // }

    // }

   // created(){
   //   this.getList();
   //
   //
   //  }




<style lang="less" scoped>
.a{
  text-decoration: none;
}
.uploader-example {
  width: 880px;
  padding: 15px;
  margin: 40px auto 0;
  font-size: 12px;
  box-shadow: 0 0 10px rgba(0, 0, 0, .4);
}
.uploader-example .uploader-btn {
  margin-right: 4px;
}
.uploader-example .uploader-list {
  max-height: 440px;
  overflow: auto;
  overflow-x: hidden;
  overflow-y: auto;
}
.router-link-active {
  text-decoration: none;
}

</style>
